package com.smartao.base.config;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.smartao.core.mvc.BaseAction;
import com.smartao.core.mvc.ResultStatus;
@Controller
@Scope("prototype")
@Results({ @Result(name = BaseAction.SUCCESS, location = "notification.jsp"),
	@Result(name = BaseAction.JSON, type="json",params={"root","resultStatus"})})
public class NotificationConfigAction extends BaseAction{

	private static final long serialVersionUID = 219191009779981363L;

	@Autowired
	private ConfigService configService;
	
	private EmailConfig email;
	
	private SmsConfig sms;
	
	@Override
	public String execute() throws Exception{
		email = new EmailConfig().loadConfig();
		sms = new SmsConfig().loadConfig();
		return SUCCESS;
	}
	
	public String save() throws Exception{
		try {
			configService.saveConfig(email);
			configService.saveConfig(sms);
			resultStatus = new ResultStatus(true, "设置已保存");
		} catch (Exception e) {
			resultStatus = new ResultStatus(false, "保存出错!");
			logger.error(e.getMessage(),e);
		}
		return JSON;
	}

	public EmailConfig getEmail() {
		return email;
	}

	public void setEmail(EmailConfig email) {
		this.email = email;
	}

	public SmsConfig getSms() {
		return sms;
	}

	public void setSms(SmsConfig sms) {
		this.sms = sms;
	}
	
}
